<?php
##############################################
#
#   分类
# @ Time : 2017-1-25 - 下午10:04:52
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################


namespace Home\Model;

class CategoryModel extends IndexBaseModel{
	/*分类表  */
	protected $tableName = 'category';
	
	/**
	 * 按等级获取分类数据
	 */
	public function getCategoryLevel($pid){
		return $this->field('cname,cid')->where(array('pid'=>$pid,'is_display'=>1))->order('sort asc')->select();
	}
	
	public function getCategoryPid($cid){
 		$result = $this -> field('pid') -> where(array('cid'=>$cid)) -> find();
 		return $result['pid'];
	}
	
	/**
	 * 获取所有的子分类
	 * @param int $cid
	 * @return array
	 */
	public function getSonCategory($cid){
		$result = $this -> field('cid') -> where(array('pid'=>$cid)) -> select();
		if(is_null($result)){
			$result = array(array('cid' => $cid));
		}
		return $result;
	}
	
}